package cn.kgm.user.server.abs.strategy;

import cn.kgm.core.exception.BizException;
import cn.kgm.user.server.abs.UserAbs;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

/**
 * #技术改变自己
 *
 * @author: kappi
 * @email: yolo.jk@qq.com
 * @date: 2024/4/9 23:06周二
 * @package: cn.kgm.user.server.abs.strategy.UserStrategy
 */
@Slf4j
@Component
public class UserStrategy {

    @Resource
    private final Map<String, UserAbs> userAbsMap = new ConcurrentHashMap<>();

    public UserAbs get(String name){
        if (userAbsMap.size() == 0) {
            log.error("[UserStrategy::get] userAbsMap uninitialized!");
            throw new BizException("userAbsMap uninitialized!");
        }
        return Optional.ofNullable(userAbsMap.get(name))
                .orElseThrow(() -> new BizException("userAbsMap is get null [{}]!",name));
    }
}
